package com.snopy.pojo;

import java.io.Serializable;
import java.time.LocalDate;
import java.time.Month;
import java.util.*;

/**
 * @author snopy
 * @version 1.0.0
 * @classname Person
 * @description
 * @email 77912204@qq.com
 * @date 2022/07/22 10:42
 */
public class Person implements Serializable {
    private static final long serialVersionUID = -2118818579464285822L;

    public enum Sex{
        MALE,FEMALE
    }
    String name;
    LocalDate birthday;
    Sex gender;
    String emailAddress;

    public Person() {
    }

    public Person(String name, LocalDate birthday, Sex gender, String emailAddress) {
        this.name = name;
        this.birthday = birthday;
        this.gender = gender;
        this.emailAddress = emailAddress;
    }

    public static int comparePerson(Person a,Person b){
        return a.birthday.compareTo(b.birthday);
    }
    public static List<Person> createPerson(int num){
        List<Person> roster = new ArrayList<>();
        Calendar calendar = Calendar.getInstance();
        Random random = new Random(20);

        for (int i = 0; i < num; i++) {
            Person person = new Person("person"+i,LocalDate.of(calendar.get(Calendar.YEAR)-random.nextInt(40),
                    Month.MAY,1),
                    getSex(),
                    "8888" + i + "@gmail" + ".com");
            roster.add(person);
        }
        return roster;
    }
    public static List<Person> createLinkedPerson(int num){
        List<Person> roster = new LinkedList<>();
        Calendar calendar = Calendar.getInstance();
        Random random = new Random(20);

        for (int i = 0; i < num; i++) {
            Person person = new Person("person"+i,LocalDate.of(calendar.get(Calendar.YEAR)-random.nextInt(40),
                    Month.MAY,1),
                    getSex(),
                    "8888"+i+
                            "@gmail" +
                            ".com");
            roster.add(person);
        }
        return roster;
    }
    public int getAge(){
        Calendar calendar = Calendar.getInstance();
        return calendar.get(Calendar.YEAR)-birthday.getYear();
    }
    public void printPerson(){
        System.out.println("hashcode: "+this.hashCode()+this.hashCode()+"name:"+this.getName()+"\t age:"+this.getAge()+"\t gender:"+this.getGender()+"\t " +
                "email:"+this.getEmailAddress());
    }
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public LocalDate getBirthday() {
        return birthday;
    }

    public void setBirthday(LocalDate birthday) {
        this.birthday = birthday;
    }

    public Sex getGender() {
        return gender;
    }

    public void setGender(Sex gender) {
        this.gender = gender;
    }

    public String getEmailAddress() {
        return emailAddress;
    }

    public void setEmailAddress(String emailAddress) {
        this.emailAddress = emailAddress;
    }
    private static Sex getSex(){
        Random random = new Random(Calendar.getInstance().getTime().getTime());
        if (random.nextInt(100)%2==0){
            return Sex.FEMALE;
        }else {
            return Sex.MALE;
        }
    }
    public static void main(String[] args) {
        Calendar calendar = Calendar.getInstance();
        System.out.println(calendar.get(Calendar.YEAR));
        Random random = new Random(Calendar.getInstance().getTime().getTime());
        System.out.println(random.nextInt(20));

    }

}
